#ifndef GLOBALDEVICE_H
#define GLOBALDEVICE_H

#include "gd32f4xx.h"
#include "gd32f4xx_rcu.h"
#include "gd32f4xx_dma.h"
#include "gd32f4xx_usart.h"
#include "gd32f4xx_gpio.h"
#include <stdint.h>

typedef enum
{
    LED1 = 0,
    LED2 = 1,
    LED3 = 2,
    LED4 = 3,
    DEVICE_PIN_MAX = 4,
} device_enum_t;

typedef enum
{
    DEVICE_MODE_OUTPUT = 0,
    DEVICE_MODE_OUTPUT_PULLUP = 1,
    DEVICE_MODE_OUTPUT_PULLDOWN = 2,
    DEVICE_MODE_INPUT = 3,
    DEVICE_MODE_INPUT_PULLUP = 4,
    DEVICE_MODE_INPUT_PULLDOWN = 5,
    DEVICE_MODE_MAX = 6,
} device_mode_enum_t;
// 外设引脚和端口结构体
typedef struct
{
    uint32_t port;
    uint32_t pin;
    device_mode_enum_t mode;
    uint8_t invert;
} device_pin_t;

#define HAL_BIT_SET(device_enum) device_pin[device_enum].invert ? gpio_bit_reset(device_pin[device_enum].port, device_pin[device_enum].pin) : gpio_bit_set(device_pin[device_enum].port, device_pin[device_enum].pin)
#define HAL_BIT_RESET(device_enum) device_pin[device_enum].invert ? gpio_bit_set(device_pin[device_enum].port, device_pin[device_enum].pin) : gpio_bit_reset(device_pin[device_enum].port, device_pin[device_enum].pin)
#define HAL_BIT_TOGGLE(device_enum) gpio_bit_toggle(device_pin[device_enum].port, device_pin[device_enum].pin)
#define USART0_DATA_ADDRESS (USART0 + 0x04U)
extern device_pin_t device_pin[DEVICE_PIN_MAX];
void device_pin_init(void);

#endif /* GLOBALDEVICE_H */
